Hello everybody. find
function for the skip list: find function cannot find entries in the skip list, even if I create it with the createString
. SystemAdmin - Mon Feb 25 15:45:15 EST 2013 |
Re: Skip list "find" function
Hi Skip skpSomeData = createString(); put(skpSomeData , "one", 1 "");
|
Re: Skip list "find" function SystemAdmin - Tue Feb 26 03:31:19 EST 2013
Hi Skip skpSomeData = createString(); put(skpSomeData , "one", 1 "");
You CAN store integers in Skip data.
Skip s = createString
int i = 0
put(s, "one", 1)
put(s, "two", 2)
for i in s do
{
print (string key s) " " i "\n"
}
if (find(s, "one", i)) print i ""
|
Re: Skip list "find" function Tony_Goodman - Tue Feb 26 04:52:26 EST 2013
You CAN store integers in Skip data.
Skip s = createString
int i = 0
put(s, "one", 1)
put(s, "two", 2)
for i in s do
{
print (string key s) " " i "\n"
}
if (find(s, "one", i)) print i ""
|
Re: Skip list "find" function |
Re: Skip list "find" function It would be easier to debug if you specified what "strange" behavior, and posted the code. -Louie |
Re: Skip list "find" function SystemAdmin - Tue Feb 26 08:08:52 EST 2013
ok, I was probably too short before. I do use find in a few routines and it looks like it works just fine exept one place, which makes me crazy, because on the first glance I impement it the usual way. Skip SWCNames = createString() ...all other definitions ... ReadSystags(Systg_ptr,SWCNames,SWCi,io4sys_tags)
bool ReadSystags(Module &Md_ptr, Skip &SWCNames,int &SWCi,Stream &io4dst_log)
{
if(null Md_ptr) {
io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
return false
}
Object o = null
Buffer tmp = create
string SWC = ""
int cur_SWCi=SWCi
bool find_status = false
for o in Md_ptr do
{
SWC = o."SWC - out"
string stmp = ""
stmp = SWC
find_status = find(SWCNames,stmp,cur_SWCi)
if(!find_status) //if found, sets SWCi to the id of the SWCName
{
//if not found add new SWC and its id
cur_SWCi++
if(put(SWCNames,SWC "",cur_SWCi))
{io4dst_log << "cannot add new entry to the list of SWC names\n" } else { io4dst_log << "Ok\n"}
}
..... some more stuff .....
}
delete tmp
SWCi=cur_SWCi
return true
}
|
Re: Skip list "find" function SystemAdmin - Mon Mar 04 05:59:26 EST 2013
ok, I was probably too short before. I do use find in a few routines and it looks like it works just fine exept one place, which makes me crazy, because on the first glance I impement it the usual way. Skip SWCNames = createString() ...all other definitions ... ReadSystags(Systg_ptr,SWCNames,SWCi,io4sys_tags)
bool ReadSystags(Module &Md_ptr, Skip &SWCNames,int &SWCi,Stream &io4dst_log)
{
if(null Md_ptr) {
io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
return false
}
Object o = null
Buffer tmp = create
string SWC = ""
int cur_SWCi=SWCi
bool find_status = false
for o in Md_ptr do
{
SWC = o."SWC - out"
string stmp = ""
stmp = SWC
find_status = find(SWCNames,stmp,cur_SWCi)
if(!find_status) //if found, sets SWCi to the id of the SWCName
{
//if not found add new SWC and its id
cur_SWCi++
if(put(SWCNames,SWC "",cur_SWCi))
{io4dst_log << "cannot add new entry to the list of SWC names\n" } else { io4dst_log << "Ok\n"}
}
..... some more stuff .....
}
delete tmp
SWCi=cur_SWCi
return true
}
I can guarantee you that the skip lists, the very core of DXL work as expected.
... find_status = find(SWCNames,SWC ,cur_SWCi) ...
// You do not need to pass the skip as a reference, when you do not allocate it inside the function
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
if(null Md_ptr) {
io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
return false
}
Object o = null
Buffer tmp = create
string SWC = ""
int cur_SWCi=SWCi // Good: You need to dereference the SWCi reference, before putting it in the skip
bool find_status = false
for o in Md_ptr do { // Current Filter should be evaluated?
SWC = o."SWC - out"
// Do not overwrite cur_SWCi here!?
if( !find(SWCNames,SWC) ) {
cur_SWCi++
// put returns true if the item did not exist and could be added
if(! put(SWCNames, SWC, cur_SWCi) ) {
io4dst_log << "cannot add new entry to the list of SWC names\n"
} else {
io4dst_log << "Ok\n"
}
}
..... some more stuff .....
}
delete tmp
SWCi = cur_SWCi
return true
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Skip list "find" function Mathias Mamsch - Mon Mar 04 07:18:08 EST 2013
I can guarantee you that the skip lists, the very core of DXL work as expected.
... find_status = find(SWCNames,SWC ,cur_SWCi) ...
// You do not need to pass the skip as a reference, when you do not allocate it inside the function
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
if(null Md_ptr) {
io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
return false
}
Object o = null
Buffer tmp = create
string SWC = ""
int cur_SWCi=SWCi // Good: You need to dereference the SWCi reference, before putting it in the skip
bool find_status = false
for o in Md_ptr do { // Current Filter should be evaluated?
SWC = o."SWC - out"
// Do not overwrite cur_SWCi here!?
if( !find(SWCNames,SWC) ) {
cur_SWCi++
// put returns true if the item did not exist and could be added
if(! put(SWCNames, SWC, cur_SWCi) ) {
io4dst_log << "cannot add new entry to the list of SWC names\n"
} else {
io4dst_log << "Ok\n"
}
}
..... some more stuff .....
}
delete tmp
SWCi = cur_SWCi
return true
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
thanks for the prompt answer. As to logical part: yes, that is correct and intended, that I get the cur_SWCi back if the entry exists - i use it further in the part of code "...some more stuff...". I do have one more counter(which is not shown here), which holds the last id. Yes, that is my typo with the inverted condition for "put" - this chunk of code was rewritten lot of times to understand the problem I have. And after that the question still remains: why the "find" routine returns false for the existing entries in the skip list? The funny thing about it is, if I use "create" instead of "createString" in the skip list init, I get expected behaviour, but invalid Id.. Nevertheless, I will try your implementation and give a feedback. Alex. |
Re: Skip list "find" function SystemAdmin - Mon Mar 04 05:59:26 EST 2013
ok, I was probably too short before. I do use find in a few routines and it looks like it works just fine exept one place, which makes me crazy, because on the first glance I impement it the usual way. Skip SWCNames = createString() ...all other definitions ... ReadSystags(Systg_ptr,SWCNames,SWCi,io4sys_tags)
bool ReadSystags(Module &Md_ptr, Skip &SWCNames,int &SWCi,Stream &io4dst_log)
{
if(null Md_ptr) {
io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
return false
}
Object o = null
Buffer tmp = create
string SWC = ""
int cur_SWCi=SWCi
bool find_status = false
for o in Md_ptr do
{
SWC = o."SWC - out"
string stmp = ""
stmp = SWC
find_status = find(SWCNames,stmp,cur_SWCi)
if(!find_status) //if found, sets SWCi to the id of the SWCName
{
//if not found add new SWC and its id
cur_SWCi++
if(put(SWCNames,SWC "",cur_SWCi))
{io4dst_log << "cannot add new entry to the list of SWC names\n" } else { io4dst_log << "Ok\n"}
}
..... some more stuff .....
}
delete tmp
SWCi=cur_SWCi
return true
}
[1] Skip "find" searches for the KEY and (if found) returns that KEY's DATA.
string Key = "AA",
Data = "DataForAA",
DataInSkip = ""
if (!find(skp, Key, DataInSkip))
then put (skp, Key, Data)
else print "Key " Key " already exists, data = " DataInSkip "\n"
- Skip skpMods = create() // KEY: 'int' Sequence; DATA: 'string' NameModule - Skip skpName = createString() // KEY and DATA: both 'string' NameModule
|
Re: Skip list "find" function Mathias Mamsch - Mon Mar 04 07:18:08 EST 2013
I can guarantee you that the skip lists, the very core of DXL work as expected.
... find_status = find(SWCNames,SWC ,cur_SWCi) ...
// You do not need to pass the skip as a reference, when you do not allocate it inside the function
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
if(null Md_ptr) {
io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
return false
}
Object o = null
Buffer tmp = create
string SWC = ""
int cur_SWCi=SWCi // Good: You need to dereference the SWCi reference, before putting it in the skip
bool find_status = false
for o in Md_ptr do { // Current Filter should be evaluated?
SWC = o."SWC - out"
// Do not overwrite cur_SWCi here!?
if( !find(SWCNames,SWC) ) {
cur_SWCi++
// put returns true if the item did not exist and could be added
if(! put(SWCNames, SWC, cur_SWCi) ) {
io4dst_log << "cannot add new entry to the list of SWC names\n"
} else {
io4dst_log << "Ok\n"
}
}
..... some more stuff .....
}
delete tmp
SWCi = cur_SWCi
return true
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
I don't exactly understand where the problem was, but there's no problem with the skip list any more. |
Re: Skip list "find" function Mathias Mamsch - Mon Mar 04 07:18:08 EST 2013
I can guarantee you that the skip lists, the very core of DXL work as expected.
... find_status = find(SWCNames,SWC ,cur_SWCi) ...
// You do not need to pass the skip as a reference, when you do not allocate it inside the function
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
if(null Md_ptr) {
io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
return false
}
Object o = null
Buffer tmp = create
string SWC = ""
int cur_SWCi=SWCi // Good: You need to dereference the SWCi reference, before putting it in the skip
bool find_status = false
for o in Md_ptr do { // Current Filter should be evaluated?
SWC = o."SWC - out"
// Do not overwrite cur_SWCi here!?
if( !find(SWCNames,SWC) ) {
cur_SWCi++
// put returns true if the item did not exist and could be added
if(! put(SWCNames, SWC, cur_SWCi) ) {
io4dst_log << "cannot add new entry to the list of SWC names\n"
} else {
io4dst_log << "Ok\n"
}
}
..... some more stuff .....
}
delete tmp
SWCi = cur_SWCi
return true
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
I have two questions regarding your comments, Mathias:
|
Re: Skip list "find" function SystemAdmin - Wed Mar 06 10:50:15 EST 2013 I have two questions regarding your comments, Mathias:
If you read my post again, the problem with your code was described there: Hello (cur_SWCi = 1) World (cur_SWCi = 2) Hello (cur_SWCi = 1) <<-- find resets the curSWCi to 1 DXL (cur_SWCi = 2) <<-- here the next new value will get 2 instead of 3 .. Passing a Skip by reference is only necessary if you want to reallocate it, not if you want to use it. Example:
void get123 (Skip &sk) {
Skip deref = sk // dereference for null check
if (null deref) sk = create()
put (sk, 1,1, true)
put (sk, 2,2, true)
put (sk, 3,3, true)
}
Skip sk = null
// since sk is passed by reference you reallocating it, will change the sk variable
// this would not happen if sk was passed by value
get123(sk)
int i; if (find(sk, 1, i)) print "Found: 1->" i "\n"
for o in entire mod do {
if (isDeleted o) continue
// if (cell o || row o || table o) continue // depending if you want to take into account table cells
...
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Skip list "find" function Mathias Mamsch - Wed Mar 06 16:27:31 EST 2013
If you read my post again, the problem with your code was described there: Hello (cur_SWCi = 1) World (cur_SWCi = 2) Hello (cur_SWCi = 1) <<-- find resets the curSWCi to 1 DXL (cur_SWCi = 2) <<-- here the next new value will get 2 instead of 3 .. Passing a Skip by reference is only necessary if you want to reallocate it, not if you want to use it. Example:
void get123 (Skip &sk) {
Skip deref = sk // dereference for null check
if (null deref) sk = create()
put (sk, 1,1, true)
put (sk, 2,2, true)
put (sk, 3,3, true)
}
Skip sk = null
// since sk is passed by reference you reallocating it, will change the sk variable
// this would not happen if sk was passed by value
get123(sk)
int i; if (find(sk, 1, i)) print "Found: 1->" i "\n"
for o in entire mod do {
if (isDeleted o) continue
// if (cell o || row o || table o) continue // depending if you want to take into account table cells
...
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
thank you for the answers. My comments, to your comments: Actually, I use cur_SWCi the way I used it before - if the key is found in the skip list, cur_SWCi shall became the data of this key. To track the IDs, there is one more variable. That is why I didn't exactly understand where the error was. Passing Skip List as a reference: I am from the C/C++ world, so passing by reference means, I have acces to the data over the pointer. Passing by value means I copy the value to the subfunction. From your explanation I've got a feeling in dxl it works different. Good Hint about filters - I will use it from now. |
Re: Skip list "find" function SystemAdmin - Thu Mar 07 04:50:54 EST 2013
Regarding references: It works the same as in C/C++. If you for example take a struct like FILE in C/c++ and pass it by value to a function, than C/C++ will copy the whole object (i.e. all members) on the stack. So any change to the members inside a function will not have any effect on the original object.
struct Buffer {
void *memory;
}
struct Skip {
void *memory;
}
...
That means, when you pass one of those types by value to a function, you are internally passing a pointer to the same memory. Therefore any function that operates on those types will modify the same internal data structure. So why would you ever want to pass one of those objects by reference? The only reason to do so, is if you want to reallocate the object. If you allocate a new Buffer from DXL:
Buffer buf = create()
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Skip list "find" function Tony_Goodman - Tue Feb 26 04:52:26 EST 2013
You CAN store integers in Skip data.
Skip s = createString
int i = 0
put(s, "one", 1)
put(s, "two", 2)
for i in s do
{
print (string key s) " " i "\n"
}
if (find(s, "one", i)) print i ""
You CAN also use integers as a key in a skip list if you (postpend ??) them with ""
Skip s = createString
|
Re: Skip list "find" function Mark@V - Wed Jan 25 04:33:45 EST 2017 You CAN also use integers as a key in a skip list if you (postpend ??) them with ""
Skip s = createString
yes, of course, but why would you want to do that? When you design a skip list, the outcome of your design should be the types of your key and data. You will program all functions using this skip list with the design in mind. If you have a Skip list which uses integers as key, you will create the list using "skMySkip = create()", if the keys are strings, you will do "skMySkip = createString()". To answer my question: Well, you might want to program generic functions that work on all skip lists and to ease work, you decide that all skip lists have strings as key. But whether this design is really useful depends on your requirements...
|